home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Tcl-Tk 8.0 / Pre-installed version / tcl8.0 / win / tclWinPort.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-15  |  9.4 KB  |  400 lines  |  [TEXT/CWIE]

  1. /*
  2.  * tclWinPort.h --
  3.  *
  4.  *    This header file handles porting issues that occur because of
  5.  *    differences between Windows and Unix. It should be the only
  6.  *    file that contains #ifdefs to handle different flavors of OS.
  7.  *
  8.  * Copyright (c) 1994-1996 Sun Microsystems, Inc.
  9.  *
  10.  * See the file "license.terms" for information on usage and redistribution
  11.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12.  *
  13.  * SCCS: @(#) tclWinPort.h 1.53 97/07/30 14:12:17
  14.  */
  15.  
  16. #ifndef _TCLWINPORT
  17. #define _TCLWINPORT
  18.  
  19. #include <malloc.h>
  20. #include <stdio.h>
  21.  
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <errno.h>
  25. #include <process.h>
  26. #include <signal.h>
  27. #include <winsock.h>
  28. #include <sys/stat.h>
  29. #include <sys/timeb.h>
  30. #include <time.h>
  31. #include <io.h>
  32. #include <fcntl.h>
  33. #include <float.h>
  34.  
  35. #define WIN32_LEAN_AND_MEAN
  36. #include <windows.h>
  37. #undef WIN32_LEAN_AND_MEAN
  38.  
  39. /*
  40.  * Define EINPROGRESS in terms of WSAEINPROGRESS.
  41.  */
  42.  
  43. #ifndef    EINPROGRESS
  44. #define EINPROGRESS WSAEINPROGRESS
  45. #endif
  46.  
  47. /*
  48.  * If ENOTSUP is not defined, define it to a value that will never occur.
  49.  */
  50.  
  51. #ifndef ENOTSUP
  52. #define    ENOTSUP        -1030507
  53. #endif
  54.  
  55. /*
  56.  * The following defines wrap the system memory allocation routines for
  57.  * use by tclAlloc.c.
  58.  */
  59.  
  60. #define TclpSysAlloc(size, isBin)    ((void*)GlobalAlloc(GMEM_FIXED, \
  61.                         (DWORD)size))
  62. #define TclpSysFree(ptr)        (GlobalFree((HGLOBAL)ptr))
  63. #define TclpSysRealloc(ptr, size)    ((void*)GlobalReAlloc((HGLOBAL)ptr, \
  64.                         (DWORD)size, 0))
  65.  
  66. /*
  67.  * The default platform eol translation on Windows is TCL_TRANSLATE_CRLF:
  68.  */
  69.  
  70. #define    TCL_PLATFORM_TRANSLATION    TCL_TRANSLATE_CRLF
  71.  
  72. /*
  73.  * Declare dynamic loading extension macro.
  74.  */
  75.  
  76. #define TCL_SHLIB_EXT ".dll"
  77.  
  78. /*
  79.  * Supply definitions for macros to query wait status, if not already
  80.  * defined in header files above.
  81.  */
  82.  
  83. #if TCL_UNION_WAIT
  84. #   define WAIT_STATUS_TYPE union wait
  85. #else
  86. #   define WAIT_STATUS_TYPE int
  87. #endif
  88.  
  89. #ifndef WIFEXITED
  90. #   define WIFEXITED(stat)  (((*((int *) &(stat))) & 0xff) == 0)
  91. #endif
  92.  
  93. #ifndef WEXITSTATUS
  94. #   define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff)
  95. #endif
  96.  
  97. #ifndef WIFSIGNALED
  98. #   define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff)))
  99. #endif
  100.  
  101. #ifndef WTERMSIG
  102. #   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7f)
  103. #endif
  104.  
  105. #ifndef WIFSTOPPED
  106. #   define WIFSTOPPED(stat)  (((*((int *) &(stat))) & 0xff) == 0177)
  107. #endif
  108.  
  109. #ifndef WSTOPSIG
  110. #   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xff)
  111. #endif
  112.  
  113. /*
  114.  * Define constants for waitpid() system call if they aren't defined
  115.  * by a system header file.
  116.  */
  117.  
  118. #ifndef WNOHANG
  119. #   define WNOHANG 1
  120. #endif
  121. #ifndef WUNTRACED
  122. #   define WUNTRACED 2
  123. #endif
  124.  
  125. /*
  126.  * Define MAXPATHLEN in terms of MAXPATH if available
  127.  */
  128.  
  129. #ifndef MAXPATH
  130. #define MAXPATH MAX_PATH
  131. #endif /* MAXPATH */
  132.  
  133. #ifndef MAXPATHLEN
  134. #define MAXPATHLEN MAXPATH
  135. #endif /* MAXPATHLEN */
  136.  
  137. #ifndef F_OK
  138. #    define F_OK 00
  139. #endif
  140. #ifndef X_OK
  141. #    define X_OK 01
  142. #endif
  143. #ifndef W_OK
  144. #    define W_OK 02
  145. #endif
  146. #ifndef R_OK
  147. #    define R_OK 04
  148. #endif
  149.  
  150. /*
  151.  * Define macros to query file type bits, if they're not already
  152.  * defined.
  153.  */
  154.  
  155. #ifndef S_ISREG
  156. #   ifdef S_IFREG
  157. #       define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  158. #   else
  159. #       define S_ISREG(m) 0
  160. #   endif
  161. # endif
  162. #ifndef S_ISDIR
  163. #   ifdef S_IFDIR
  164. #       define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  165. #   else
  166. #       define S_ISDIR(m) 0
  167. #   endif
  168. # endif
  169. #ifndef S_ISCHR
  170. #   ifdef S_IFCHR
  171. #       define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  172. #   else
  173. #       define S_ISCHR(m) 0
  174. #   endif
  175. # endif
  176. #ifndef S_ISBLK
  177. #   ifdef S_IFBLK
  178. #       define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  179. #   else
  180. #       define S_ISBLK(m) 0
  181. #   endif
  182. # endif
  183. #ifndef S_ISFIFO
  184. #   ifdef S_IFIFO
  185. #       define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  186. #   else
  187. #       define S_ISFIFO(m) 0
  188. #   endif
  189. # endif
  190.  
  191. /*
  192.  * Define pid_t and uid_t if they're not already defined.
  193.  */
  194.  
  195. #if ! TCL_PID_T
  196. #   define pid_t int
  197. #endif
  198. #if ! TCL_UID_T
  199. #   define uid_t int
  200. #endif
  201.  
  202. /*
  203.  * Provide a stub definition for TclGetUserHome().
  204.  */
  205.  
  206. #define TclGetUserHome(name,bufferPtr) (NULL)
  207.  
  208. /*
  209.  * Visual C++ has some odd names for common functions, so we need to
  210.  * define a few macros to handle them.  Also, it defines EDEADLOCK and
  211.  * EDEADLK as the same value, which confuses Tcl_ErrnoId().
  212.  */
  213.  
  214. #ifdef _MSC_VER
  215. #    define environ _environ
  216. #    define hypot _hypot
  217. #    define exception _exception
  218. #    undef EDEADLOCK
  219. #endif /* _MSC_VER */
  220.  
  221. /*
  222.  * The following defines redefine the Windows Socket errors as
  223.  * BSD errors so Tcl_PosixError can do the right thing.
  224.  */
  225.  
  226. #ifndef EWOULDBLOCK
  227. #define EWOULDBLOCK             EAGAIN
  228. #endif
  229. #ifndef EALREADY
  230. #define EALREADY    149    /* operation already in progress */
  231. #endif
  232. #ifndef ENOTSOCK
  233. #define ENOTSOCK    95    /* Socket operation on non-socket */
  234. #endif
  235. #ifndef EDESTADDRREQ
  236. #define EDESTADDRREQ    96    /* Destination address required */
  237. #endif
  238. #ifndef EMSGSIZE
  239. #define EMSGSIZE    97    /* Message too long */
  240. #endif
  241. #ifndef EPROTOTYPE
  242. #define EPROTOTYPE    98    /* Protocol wrong type for socket */
  243. #endif
  244. #ifndef ENOPROTOOPT
  245. #define ENOPROTOOPT    99    /* Protocol not available */
  246. #endif
  247. #ifndef EPROTONOSUPPORT
  248. #define EPROTONOSUPPORT    120    /* Protocol not supported */
  249. #endif
  250. #ifndef ESOCKTNOSUPPORT
  251. #define ESOCKTNOSUPPORT    121    /* Socket type not supported */
  252. #endif
  253. #ifndef EOPNOTSUPP
  254. #define EOPNOTSUPP    122    /* Operation not supported on socket */
  255. #endif
  256. #ifndef EPFNOSUPPORT
  257. #define EPFNOSUPPORT    123    /* Protocol family not supported */
  258. #endif
  259. #ifndef EAFNOSUPPORT
  260. #define EAFNOSUPPORT    124    /* Address family not supported */
  261. #endif
  262. #ifndef EADDRINUSE
  263. #define EADDRINUSE    125    /* Address already in use */
  264. #endif
  265. #ifndef EADDRNOTAVAIL
  266. #define EADDRNOTAVAIL    126    /* Can't assign requested address */
  267. #endif
  268. #ifndef ENETDOWN
  269. #define ENETDOWN    127    /* Network is down */
  270. #endif
  271. #ifndef ENETUNREACH
  272. #define ENETUNREACH    128    /* Network is unreachable */
  273. #endif
  274. #ifndef ENETRESET
  275. #define ENETRESET    129    /* Network dropped connection on reset */
  276. #endif
  277. #ifndef ECONNABORTED
  278. #define ECONNABORTED    130    /* Software caused connection abort */
  279. #endif
  280. #ifndef ECONNRESET
  281. #define ECONNRESET    131    /* Connection reset by peer */
  282. #endif
  283. #ifndef ENOBUFS
  284. #define ENOBUFS        132    /* No buffer space available */
  285. #endif
  286. #ifndef EISCONN
  287. #define EISCONN        133    /* Socket is already connected */
  288. #endif
  289. #ifndef ENOTCONN
  290. #define ENOTCONN    134    /* Socket is not connected */
  291. #endif
  292. #ifndef ESHUTDOWN
  293. #define ESHUTDOWN    143    /* Can't send after socket shutdown */
  294. #endif
  295. #ifndef ETOOMANYREFS
  296. #define ETOOMANYREFS    144    /* Too many references: can't splice */
  297. #endif
  298. #ifndef ETIMEDOUT
  299. #define ETIMEDOUT    145    /* Connection timed out */
  300. #endif
  301. #ifndef ECONNREFUSED
  302. #define ECONNREFUSED    146    /* Connection refused */
  303. #endif
  304. #ifndef ELOOP
  305. #define ELOOP        90    /* Symbolic link loop */
  306. #endif
  307. #ifndef EHOSTDOWN
  308. #define EHOSTDOWN    147    /* Host is down */
  309. #endif
  310. #ifndef EHOSTUNREACH
  311. #define EHOSTUNREACH    148    /* No route to host */
  312. #endif
  313. #ifndef ENOTEMPTY
  314. #define ENOTEMPTY     93    /* directory not empty */
  315. #endif
  316. #ifndef EUSERS
  317. #define EUSERS        94    /* Too many users (for UFS) */
  318. #endif
  319. #ifndef EDQUOT
  320. #define EDQUOT        49    /* Disc quota exceeded */
  321. #endif
  322. #ifndef ESTALE
  323. #define ESTALE        151    /* Stale NFS file handle */
  324. #endif
  325. #ifndef EREMOTE
  326. #define EREMOTE        66    /* The object is remote */
  327. #endif
  328.  
  329. /*
  330.  * The following define ensures that we use the native putenv
  331.  * implementation to modify the environment array.  This keeps
  332.  * the C level environment in synch with the system level environment.
  333.  */
  334.  
  335. #define USE_PUTENV    1
  336.     
  337. /*
  338.  * The following defines map from standard socket names to our internal
  339.  * wrappers that redirect through the winSock function table (see the
  340.  * file tclWinSock.c).
  341.  */
  342.  
  343. #define getservbyname    TclWinGetServByName
  344. #define getsockopt    TclWinGetSockOpt
  345. #define ntohs        TclWinNToHS
  346. #define setsockopt    TclWinSetSockOpt
  347.  
  348. /*
  349.  * The following implements the Windows method for exiting the process.
  350.  */
  351. #define TclPlatformExit(status) exit(status)
  352.  
  353.  
  354. /*
  355.  * The following declarations belong in tclInt.h, but depend on platform
  356.  * specific types (e.g. struct tm).
  357.  */
  358.  
  359. EXTERN struct tm *    TclpGetDate _ANSI_ARGS_((const time_t *tp,
  360.                 int useGMT));
  361. EXTERN unsigned long    TclpGetPid _ANSI_ARGS_((Tcl_Pid pid));
  362. EXTERN size_t        TclStrftime _ANSI_ARGS_((char *s, size_t maxsize,
  363.                 const char *format, const struct tm *t));
  364.  
  365. /*
  366.  * The following prototypes and defines replace the Windows versions
  367.  * of POSIX function that various compilier vendors didn't implement 
  368.  * well or consistantly.
  369.  */
  370.  
  371. #define stat(path, buf)        TclWinStat(path, buf)
  372. #define lstat            stat
  373. #define access(path, mode)    TclWinAccess(path, mode)
  374.  
  375. EXTERN int        TclWinStat _ANSI_ARGS_((CONST char *path, 
  376.                 struct stat *buf));
  377. EXTERN int        TclWinAccess _ANSI_ARGS_((CONST char *path, 
  378.                 int mode));
  379.  
  380. #define TclpReleaseFile(file)    ckfree((char *) file)
  381.  
  382. /*
  383.  * Declarations for Windows specific functions.
  384.  */
  385.  
  386. EXTERN void        TclWinConvertError _ANSI_ARGS_((DWORD errCode));
  387. EXTERN void        TclWinConvertWSAError _ANSI_ARGS_((DWORD errCode));
  388. EXTERN struct servent * PASCAL FAR
  389.             TclWinGetServByName _ANSI_ARGS_((const char FAR *nm,
  390.                     const char FAR *proto));
  391. EXTERN int PASCAL FAR    TclWinGetSockOpt _ANSI_ARGS_((SOCKET s, int level,
  392.                     int optname, char FAR * optval, int FAR *optlen));
  393. EXTERN HINSTANCE    TclWinGetTclInstance _ANSI_ARGS_((void));
  394. EXTERN HINSTANCE    TclWinLoadLibrary _ANSI_ARGS_((char *name));
  395. EXTERN u_short PASCAL FAR
  396.             TclWinNToHS _ANSI_ARGS_((u_short ns));
  397. EXTERN int PASCAL FAR    TclWinSetSockOpt _ANSI_ARGS_((SOCKET s, int level,
  398.                     int optname, const char FAR * optval, int optlen));
  399. #endif /* _TCLWINPORT */
  400.